﻿function startmarquee(elementID,h,speed,delay){
	var t = null;
	var p = false;
	var box = document.getElementById(elementID);
	if(!box) return;
	box.innerHTML += box.innerHTML;
	box.onmouseover = function(){p = true};
	box.onmouseout = function(){p = false};
	box.scrollTop = 0;
	function start(){
		 t = setInterval(scrolling,speed);
		 if(!p){
			box.scrollTop += 2;
		}
	}
	function scrolling(){
		if(p) return;
		if(box.scrollTop % h != 0){
			box.scrollTop += 2;
			if(box.scrollTop >= box.scrollHeight/2) box.scrollTop = 0;
		}
		else{
			clearInterval(t);
			setTimeout(start,delay);
		}
	}
	setTimeout(start,delay);
}
startmarquee('box',30,20,1000);

//IE6用absolute值不断变化模拟fixed
var isIE6 = !-[1,] && !window.XMLHttpRequest;
var position = function(){
		html = document.getElementsByTagName('html')[0];
	if (isIE6 && document.body.currentStyle.backgroundAttachment !== 'fixed') {
		html.style.backgroundImage = 'url(about:blank)';
		html.style.backgroundAttachment = 'fixed';
	};
	return {
		fixed: isIE6 ? function(elem){
				var style = elem.style,
					dom = '(document.documentElement)',
					left = parseInt(style.left) - document.documentElement.scrollLeft,
					top = parseInt(style.top) - document.documentElement.scrollTop;
				this.absolute(elem);
				style.setExpression('left', 'eval(' + dom + '.scrollLeft + ' + left + ') + "px"');
				style.setExpression('top', 'eval(' + dom + '.scrollTop + ' + top + ') + "px"');
			} : function(elem){
				elem.style.position = 'fixed';
		},
		absolute: isIE6 ? function(elem){
				var style = elem.style;
				style.position = 'absolute';
				style.removeExpression('left');
				style.removeExpression('top');
			} : function(elem){
				elem.style.position = 'absolute';
		}
	};
}();

function openWin(o){
	var $o = $('#'+o),
		w =  document.documentElement.clientWidth,
		h =  document.documentElement.clientHeight,
		boxLeft = (w - $o.width() )/2 +'px',
		sh = isIE6? document.documentElement.scrollTop:0,
		boxTop = (h - $o.height())/2 + sh - 100+'px';
	$o.css({'top':boxTop, 'left':boxLeft}).show();
	var box = document.getElementById(o);
	position.fixed(box);
	//add overlay
	if($('#overlay').length>0){
		$('#overlay').show();
	}else{
		var	h =  Math.max(document.body.clientHeight, document.documentElement.clientHeight),
			iFrame = isIE6? '<iframe style="width:100%;height:' + h + '"frameborder="0"></iframe>':'';
		$('#append_parent').append('<div id="overlay" style="z-index:1984;width:100%;height:'+ h +'px;background:#000;opacity:.2;filter:alpha(Opacity:20);">'+ iFrame +'</div>');
	}
	var overlay = document.getElementById('overlay');
	position.fixed(overlay);
	return false;
}
function closeWin(o){
	$('#overlay').hide();
	$('#'+o).hide();
	return false;
}